﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using ByteSite.Common;

namespace ByteSite.BLL
{
    /// <summary>
    ///所属站点的OAuth登录表
    /// </summary>
    public partial class site_oauth
    {
        private readonly Entitys.sysconfig sysConfig = new BLL.sysconfig().loadConfig();//获得系统配置信息
        private readonly DAL.Data data;
        private readonly DAL.site_oauth dal;

        public site_oauth()
        {
            data = new DAL.Data();
            dal = new DAL.site_oauth(sysConfig.sysdatabaseprefix);
        }

        #region 基本方法================================
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return data.Exists<Entitys.dt_site_oauth>(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Entitys.dt_site_oauth model)
        {
            return data.Insert(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Entitys.dt_site_oauth model)
        {
            return data.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            return data.Delete<Entitys.dt_site_oauth>(id);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Entitys.dt_site_oauth GetModel(int id)
        {
            return data.Get<Entitys.dt_site_oauth>(id);
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public List<Entitys.dt_site_oauth> GetList(int top, Expression<Func<Entitys.dt_site_oauth, bool>> whereExpression)
        {
            return dal.GetList(top, whereExpression);
        }

        public List<Entitys.dt_site_oauth> GetList(int top, string strWhere)
        {
            return dal.GetList(top, strWhere);
        }

        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public List<Entitys.dt_site_oauth> GetList(int pageSize, int pageIndex, Expression<Func<Entitys.dt_site_oauth, bool>> whereExpression, string filedOrder, out int recordCount)
        {
            return dal.GetList(pageSize, pageIndex, whereExpression, out recordCount);
        }
        #endregion

        #region 扩展方法================================
        /// <summary>
        /// 返回标题名称
        /// </summary>
        public string GetTitle(int id)
        {
            Entitys.dt_site_oauth model = data.Get<Entitys.dt_site_oauth>(id);
            if (model == null)
                return "";
            else
                return model.title;
        }

        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(Expression<Func<Entitys.dt_site_oauth, Entitys.dt_site_oauth>> expression, Expression<Func<Entitys.dt_site_oauth, bool>> whereExpression)
        {
            return data.UpdateColumns<Entitys.dt_site_oauth>(expression, whereExpression);
        }
        #endregion
    }
}